package com.googlecode.eightqueenshaggle;

import java.util.ArrayList;

import org.haggle.Attribute;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class HaggleTestViewController extends Activity implements OnClickListener{

	Button button1,button2,button3,button4;
	
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.haggle_test);
		

	    //
		button1 = (Button) findViewById(R.id.Bt1);
		button2 = (Button) findViewById(R.id.Bt2);
		button3 = (Button) findViewById(R.id.Bt3);
		button4 = (Button) findViewById(R.id.Bt4);

		button1.setOnClickListener(this);
		button2.setOnClickListener(this);
		button3.setOnClickListener(this);
		button4.setOnClickListener(this);
	    //
		
	}
	
	

	//test attr
	Attribute a;	
	public void onClick(View v) {
	    
		//"register interest", "unregister interest", "shutdown" "create obj"
		if (v == button1) {
			


			a=new Attribute("puzzleName", "EQclassicalPuzzle", 1);
			HaggleConnector.getInstance().getHaggleHandle().registerInterest(a);
			
			ArrayList<Attribute> aa = new ArrayList<Attribute>();

			aa.add(new Attribute("Picture", "a", 1));
			aa.add(new Attribute("Picture", "b", 1));
		/*	for (int i = 0; i < attrs.length; i++) {

				// Also add to our interest list in the interest view
				synchronized (InterestView.interests) {
					if (InterestView.interests.contains(attrs[i]) == false) {
						InterestView.interests.add(attrs[i]);
						aa.add(new Attribute("Picture", attrs[i], 1));
					}
				}
			}*/
			if (HaggleConnector.getInstance().getHaggleHandle().registerInterests(
					aa.toArray(new Attribute[aa.size()]))==0) Log.d("return value", "0");

		} else if (v == button2) {
						
			HaggleConnector.getInstance().getHaggleHandle().unregisterInterest(a);
		
		} else if (v == button3) {
			HaggleConnector.getInstance().shutdownHaggle();
		} else if (v == button4) {
			
			Puzzle tPuzzle = new Puzzle(8, 8, 8, 91, "EQclassicalPuzzle");
			Solution tSolution = new Solution(tPuzzle);
			
			tSolution.queensLocations.add(new Coord(42,23));
			tSolution.queensLocations.add(new Coord(1111,815));
			tSolution.queensLocations.add(new Coord(1234,3311));
			
			SolutionObject solObj= new SolutionObject(tPuzzle, tSolution, "Ying");
			HaggleConnector.getInstance().pushSolutionObject(solObj);
		} 
		
	}	
	
	
}
